package org.robot.scm.platform.server.handler;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 自毁程序
 */
@Slf4j
@NoArgsConstructor
public class SelfDestroyHandler extends BaseHandler implements HttpHandler {

    @Override
    public String getUri() {
        return "/selfDestroy";
    }

    @Override
    public void handle(HttpExchange exchange) throws IOException {
        if (!exchange.getRequestMethod().equalsIgnoreCase("GET")) {
            sendFailureResponse(exchange, "请求非法");
            return;
        }

        // 当启动一个新的进程的时候当前系统直接退出
        ProcessBuilder processBuilder = new ProcessBuilder("cmd", "/c", "start", "/min", "C:\\Users\\Administrator\\.scm\\self.bat");
        try {
            processBuilder.start();
        } catch (IOException e) {
            log.error("error", e);
        }

        sendSuccessResponse(exchange, "自毁成功");
    }

}
